package com.wltjack.controller;

import com.wltjack.common.Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.NoPermissionException;

/**
 * 异常测试
 */
@RestController
@RequestMapping("/exception")
public class ExceptionController {

    /**
     * 异常测试
     * http://127.0.0.1:8080/learn/exception/testArithmeticException
     */
    @GetMapping("/testArithmeticException")
    public Response testArithmeticException(){
        int x = 1 / 0;
        return new Response(x);
    }

    /**
     * 异常测试
     * http://127.0.0.1:8080/learn/exception/testNoPermissionException
     * @throws NoPermissionException
     */
    @GetMapping("/testNoPermissionException")
    public String testNoPermissionException() throws NoPermissionException {
        if (1 == 1) {
            throw new NoPermissionException("没有权限");
        }
        return "ok";
    }


}
